<template>
  <basic-container>
    <page-header-tool title="物料主数据" :btns="modBtns" :max="2">
    </page-header-tool>
    <avue-crud
      class="avue-affixed avue-new-table"
      ref="crud"
      :page.sync="page"
      :data="tableData"
      :option="tableOption"
      :table-loading="listLoading"
      @current-change="currentChange"
      @size-change="sizeChange"
      @selection-change="selectionChange"
      @search-change="searchChange"
      @filter-change="filterChange"
    >
      <template slot-scope="scope" slot="menu">
        <table-column-btns :btns="tableBtns" :scope="scope"></table-column-btns>
      </template>
    </avue-crud>
  </basic-container>
</template>
<script>
import { tableOption } from "./const/options";
import { materialListData } from "./const/data.js";
export default {
  name: "material",
  data() {
    return {
      tableOption: tableOption,
      listLoading: false,
      tableData: [],
      page: {
        total: 0, // 总页数
        currentPage: 1, // 当前页数
        pageSize: 10, // 每页显示多少条
      },
      modBtns: [
        {
          name: "新增",
          click: this.handleCreate,
        },
        {
          name: "导入",
          type: "success",
          click: this.handleImport,
        },
      ],
      tableBtns: [
        {
          name: "查看",
          click: this.handleLook,
        },
        {
          name: "编辑",
          click: this.handleUpdate,
        },
      ],
    };
  },
  created() {
    this.getList();
  },
  methods: {
    filterChange(filters) {
      console.log("filterChange===>", filters);
      this.searchCondition = Object.assign(this.searchCondition, filters);
      this.page.currentPage = 1;
      this.page.pageSize = 10;
      this.getList();
    },
    async searchChange(form, done) {
      this.searchCondition = form;
      console.log(form);
      await this.getList();
      done();
    },
    getList() {
      this.tableData = materialListData.records;
      this.page.total = materialListData.total;
    },
    currentChange(val) {
      this.page.page = val;
      this.page.currentPage = val;
      this.getList();
    },
    sizeChange(val) {
      this.page.limit = val;
      this.page.pageSize = val;
      this.getList();
    },
    selectionChange(val) {
      this.selectionData = val;
    },
  },
};
</script>
